<?php
$q=$_GET["q"];
$hint='';
include_once ("../Login/databaseconnection.php");
require_once ("../Login/config.php");
$result = mysql_query("SELECT * FROM training Where Training_Name='$q'");
if($row = mysql_fetch_array($result))
{
$id=$row['Training_Id'];
$hint="<br/><font color='black'>The ID of this Training is :".$id."<br/>";
$resulttt = mysql_query("SELECT * FROM training_details Where Training_Id='$id'");
if($rowtt = mysql_fetch_array($resulttt))
{
$hint=$hint.'<br/>To view all <a href="'.$basedir.'/Trainingdetails/searchtra.php?action=training&t='.$id.'" class="searchlinks">'.$q.'</a> details<br/>';
}
$schools="";
$resultds = mysql_query("SELECT DISTINCT(Teacher_NIC) FROM training_details Where Training_Id='$id'");
while($rowds= mysql_fetch_array($resultds))
{
$nic=$rowds['Teacher_NIC'];
$resultsc = mysql_query("SELECT * FROM teacher Where T_NIC_Number='$nic'");
if($rowsc= mysql_fetch_array($resultsc))
{
$hint=$hint."<br/>To view all ".$q." Training details of ";
if(empty($schools))
{
$schools=$rowsc['School_Id'];
}
else
{
$schools=$schools.",".$rowsc['School_Id'];
}
$shid=$rowsc['School_Id'];
$resultsch = mysql_query("SELECT * FROM school Where School_Id='$shid'");
if(mysql_num_rows($resultsch)>0)
{
if($rowsch= mysql_fetch_array($resultsch))
{
$scho=$rowsch['Name'];
$addr=$rowsch['Address'];
}
}
$hint=$hint.'<a href="'.$basedir.'/Trainingdetails/searchtra.php?action=teacher&tea='.$nic.'&t='.$id.'" class="searchlinks">'.$rowsc['First_Name'].' '.$rowsc['Last_Name'];
if(mysql_num_rows($resultsch)==0)
{
$hint=$hint.' of '.$shid;
}
if(mysql_num_rows($resultsch)>0)
{
$hint=$hint.' of '.$scho.' '.$addr;
}
$hint=$hint.'</a><br/>';
}
}
$schs=explode(",",$schools);
for ($i = 0; $i <count($schs); $i++) 
{
 $temp =$schs[$i];
  $j = $i;
  for ($k = 0; $k <count($schs); $k++) 
  {
    if ($k != $j) {
      if ($temp == $schs[$k]) 
	  {
        $schs[$k]="";
      }
    }
  }
}
for($i=0;$i<count($schs);$i++)
{
$sid=$schs[$i];
$ressch = mysql_query("SELECT * FROM school Where School_Id='$sid'");
if(mysql_num_rows($ressch)>0)
{
if($rsch= mysql_fetch_array($ressch))
{
$nam=$rsch['Name'];
$adr=$rsch['Address'];
$cno=$rsch['Census_Number'];
}
}
if($sid!="")
{
$hint=$hint."<br/>To view all ".$q." Training details of ";
$hint=$hint.'<a href="'.$basedir.'/Trainingdetails/searchtra.php?action=school&t='.$id.'&s='.$sid.'" class="searchlinks">';
if(mysql_num_rows($ressch)==0)
{
$hint=$hint.$sid;
}
if(mysql_num_rows($ressch)>0)
{
$hint=$hint.$cno.' '.$nam.' '.$adr;
}
$hint=$hint.'</a><br/>';
}
}
$hint=$hint.'</font>';
}
if($hint==''||$hint=="<br/><font color='black'>The ID of this Training is :".$id."<br/></font>")
{
echo $hint."<br/>";
$response='<font class="err"><img src="../images/alert.jpg" width="12" height="12"/> There are no results found for this Training name!</font>';
}
else
{
$response=$hint;
}
echo $response;
?>